package org.bluweb.g4wicket.map.image;

import org.apache.wicket.markup.ComponentTag;
import org.bluweb.g4wicket.G4WicketImage;


@SuppressWarnings("serial")
public class GMapImage extends G4WicketImage {

	private String mapType;
	private int zoom = 14;
	private String center;
	private boolean sensor;
	
	public GMapImage( String id, String mapType, int width, int height, boolean sensor ) {
		super(id, width, height);
		this.mapType = mapType;
		this.sensor = sensor;
	}
	
	public GMapImage setZoom( int zoom ) {
		this.zoom = zoom;
		return this;
	}
	
	public GMapImage setCenter( String center ) {
		this.center = center;
		return this;
	}
	 
//	http://maps.google.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=14&size=512x512&maptype=roadmap&sensor=false
		
	protected void onComponentTag( ComponentTag tag ) {
        super.onComponentTag(tag);
        checkComponentTag(tag, "img");
        
        StringBuilder builder = new StringBuilder( "http://maps.google.com/maps/api/staticmap?" );
        builder.append( "maptype=" ).append( this.mapType );
        builder.append( "&size=" ).append( this.getWidth() ).append( 'x' ).append( this.getHeight() );
        builder.append( "&sensor=" ).append( this.sensor );
        builder.append( "&center=" ).append( this.center );
        builder.append( "&zoom=" ).append( this.zoom );
        
        tag.put( "src", builder.toString() );
    }
}
